package ca.mcgill.mni.bic;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;


public class ProgressDialog extends org.eclipse.swt.widgets.Dialog {
	
	Shell shell;
	int style;
	ProgressBar progress;
	
	public ProgressDialog(Shell shell, int style) {
		super(shell, SWT.NONE);
		this.style = style;
	}
	
	public void open(String message) {
		Shell parent = getParent();
		Shell shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
		this.shell = shell;
		shell.setText("Working...");
		
		GridLayout gridLayout = new GridLayout();
	    gridLayout.numColumns = 1;
	    shell.setLayout(gridLayout);
		
		Label label = new Label(shell, SWT.NONE);
		label.setText(message);
		
		progress = new ProgressBar(shell, SWT.HORIZONTAL | SWT.INDETERMINATE);
		progress.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		
		
		shell.layout();
		shell.setSize(400, 100);
		
		shell.open();
	}
	
	public void update() {
		if(!shell.isDisposed())
			shell.getDisplay().readAndDispatch();
	}

	public void close() {
		if(!shell.isDisposed())
			shell.close();
	}

}
